package com.example.demo.controller;

import com.example.demo.common.Result;
import com.example.demo.entity.Grade;
import com.example.demo.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/grades")
public class GradeController {
    @Autowired
    private GradeService gradeService;
    
    @GetMapping("/listAll")
    public Result<List<Grade>> listAll() {
        return Result.success(gradeService.findAll());
    }
    
    @GetMapping("/getByCourseId/{courseId}")
    public Result<List<Grade>> getByCourseId(@PathVariable Long courseId) {
        return Result.success(gradeService.findByCourseId(courseId));
    }
    
    @PostMapping("/update")
    public Result<?> update(@RequestBody Grade grade) {
        return Result.success(gradeService.save(grade));
    }
    
    @GetMapping("/getByRange/{minScore}/{maxScore}")
    public Result<List<Grade>> getByRange(
            @PathVariable Double minScore,
            @PathVariable Double maxScore) {
        return Result.success(gradeService.findByScoreRange(minScore, maxScore));
    }
} 